package com.buka.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.buka.common.BizCodeEnum;
import com.buka.constants.Constants;
import com.buka.dto.ConfirmOrderDto;
import com.buka.entity.ProductOrder;
import com.buka.service.ProductOrderService;
import com.buka.util.JsonData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (ProductOrder)表控制层
 *
 * @author makejava
 * @since 2025-08-12 14:27:51
 */
@RestController
@RequestMapping("/api/productOrder/v1")
public class ProductOrderController extends ApiController {
    @Resource
    private ProductOrderService orderService;

    @PostMapping("confirm")
    public JsonData confirmOrder(@RequestBody ConfirmOrderDto confirmOrderDto){

        JsonData result =  orderService.confirm(confirmOrderDto);

        if(result.getCode() == 0){
            //发起支付调用需要判断是那种支付方式
            if(Constants.PayTypeEnum.WECHAT.name().equals(confirmOrderDto.getPayType())){
                //todo 微信支付
            }else if(Constants.PayTypeEnum.ALIPAY.name().equals(confirmOrderDto.getPayType())){
                //todo 支付宝调用
            }else if(Constants.PayTypeEnum.BANK.name().equals(confirmOrderDto.getPayType())){
                //todo 银行
            }
            return JsonData.buildResult(BizCodeEnum.NO_PAY);
        }else{
            return JsonData.buildResult(BizCodeEnum.ORDER_ERROR);
        }
    }

    @GetMapping("queryState")
    public JsonData queryOrderState(String outTradeNo){
        return orderService.queryOrderState(outTradeNo);
    }

}

